package cc.yiueil.Interrupt;

/**
 * InterruptMethod 中断线程方法1
 *
 * @author Administrator
 * @version 1.0
 */
public class InterruptMethod {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            int n = 0;
            while (!Thread.currentThread().isInterrupted()) {
                n++;
                System.out.println(n + " hello!");
            }
            System.out.println("thread end");
        });
        t.start();
        // 暂停1毫秒 给子线程腾出资源
        Thread.sleep(1);
        // 中断t线程
        t.interrupt();
        // 等待t线程结束
        t.join();
        System.out.println("end");
    }
}
